package com.sgst.job.services.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sgst.job.enums.InstrStatusLogType;
import com.sgst.job.enums.InstrumentState;
import com.sgst.job.services.entity.CommonDict;
import com.sgst.job.services.mapper.CommonDictMapper;
import com.sgst.job.services.service.ICommonDictService;
import org.springframework.stereotype.Service;

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * <p>
 * 系统中枚举对应字典表 服务实现类
 * </p>
 *
 * @author thinking
 * @since 2020-06-30
 */
@Service
public class CommonDictServiceImpl extends ServiceImpl<CommonDictMapper, CommonDict> implements ICommonDictService {

    @Override
    public void addInstrumentStateDic() {
        String enumName = "InstrumentState";
        String enumValue = "仪器状态枚举";
        saveBatch(Stream.of(InstrumentState.values())
                .map(t-> new CommonDict()
                        .setEnumName(enumName)
                        .setEnumDesc(enumValue)
                        .setItemName(t.name())
                        .setItemDesc(t.getDescription())
                        .setItemValue(t.getStateCode())
                ).collect(Collectors.toList()));

    }

    @Override
    public void addInstrStatusLogTypeDic() {
        String enumName = "InstrStatusLogType";
        String enumValue = "仪器操作状态";
        saveBatch(Stream.of(InstrStatusLogType.values())
                .map(t-> new CommonDict()
                        .setEnumName(enumName)
                        .setEnumDesc(enumValue)
                        .setItemName(t.name())
                        .setItemDesc(t.getText())
                        .setItemValue(t.getType())
                ).collect(Collectors.toList()));
    }
}
